<template>
	<view class="operation">
		<!-- 项目管理 -->
		<view class="project_admin">
			<view class="project_title" style="margin-top: 30rpx; margin-bottom: 30rpx">
				<text>项目管理</text>
			</view>
			<view class="project_content">
				<view style="display: flex; justify-content: space-around; width: 702rpx">
					<view @click="toTransfer(0)">
						<view class="top">{{ CaluItem.traTotal }}</view>
						<view class="bottom">验收移交</view>
					</view>
					<view @click="toTransfer(1)">
						<view class="top">{{ CaluItem.traFinish }}</view>
						<view class="bottom">已完成</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 扫码收货 -->
		<view class="receiving">
			<view class="receiving_title" style="margin-top: 30rpx; margin-bottom: 30rpx">
				<text>扫码收货</text>
			</view>
			<view class="receiving_content">
				<view class="left" @click="BatchReceiving">
					<view>
						<image src="../../static/img/batch.png"></image>
					</view>
					<view style="font-size: 36rpx; margin-top: 20rpx; margin-bottom: 20rpx">
						<text>批量收货</text>
					</view>
				</view>
				<view class="right">
					<view class="single" @click="SingleCode">
						<image src="../../static/img/single.png"></image>
						<text style="margin-left: 20rpx">单个扫码</text>
					</view>
					<view class="right_content">
						<view class="region" @click="AreaReceiving">
							<image src="../../static/img/region.png"></image>
							<text>区域收货</text>
						</view>
						<view class="return" @click="BatchReturn">
							<image src="../../static/img/return.png"></image>
							<text>批量退货</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 报修订单 -->
		<view class="orders_type">
			<view class="myOrder_title">
				<text>报修订单</text>
			</view>
			<view class="myOrder_list">
				<view class="myOrder_list_item" @click="to_orderList1">
					<view class="item_img">
						<image src="../../static/img/tip1.png"></image>
					</view>
					<view class="tips" v-if="conductshow">{{ RepairOrder.tips_cond }}</view>
					<view class="item_text">确认中</view>
				</view>
				<view class="myOrder_list_item" @click="to_orderList2">
					<view class="tips" v-if="conductshow">{{ tips_conduct }}</view>
					<view class="item_img">
						<image src="../../static/img/tip2.png"></image>
					</view>
					<view class="tips" v-if="accessory">{{ RepairOrder.tips_accessory }}</view>
					<view class="item_text">配件确认</view>
				</view>
				<view class="myOrder_list_item" @click="to_orderList3">
					<view class="item_img">
						<image src="../../static/img/tip3.png"></image>
					</view>
					<view class="tips" v-if="repair">{{ RepairOrder.tips_repair }}</view>
					<view class="item_text">维修中</view>
				</view>
				<view class="myOrder_list_item" @click="to_orderList5">
					<view class="item_img">
						<image src="../../static/img/tip5.png"></image>
					</view>
					<view class="tips" v-if="confirmmoney">{{ RepairOrder.tips_confirmmoney }}</view>
					<view class="item_text">费用确认</view>
				</view>
				<view class="myOrder_list_item" @click="to_orderList4">
					<view class="item_img">
						<image src="../../static/img/tip4.png"></image>
					</view>
					<view class="tips" v-if="evalshow">{{ RepairOrder.tips_evalshow }}</view>
					<view class="item_text">已完成</view>
				</view>
			</view>
		</view>
		<!-- 巡检订单 -->
		<view class="orders_type">
			<view class="myOrder_title">
				<text>巡检订单</text>
			</view>
			<view class="myOrder_list">
				<view class="myOrder_list_item" @click="to_inorderList1">
					<view class="item_img">
						<image src="../../static/img/tip1.png"></image>
					</view>
					<view class="tips" v-if="sisconductshow">{{ InspectionOrder.sistips_cond }}</view>
					<view class="item_text">确认中</view>
				</view>
				<view class="myOrder_list_item" @click="to_inorderList2">
					<view class="item_img">
						<image src="../../static/img/tip3.png"></image>
					</view>
					<view class="tips" v-if="sisrepair">{{ InspectionOrder.sistips_repair }}</view>
					<view class="item_text">巡检中</view>
				</view>
				<view class="myOrder_list_item" @click="to_inorderList3">
					<view class="item_img">
						<image src="../../static/img/tip4.png"></image>
					</view>
					<view class="tips" v-if="sisevalshow">{{ InspectionOrder.sistips_evalshow }}</view>
					<view class="item_text">已完成</view>
				</view>
			</view>
		</view>
		<!-- 新闻动态 -->
		<view class="article" v-if="userId != ''">
			<view class="article_title">
				<view>新闻动态</view>
			</view>
			<view class="article_content">
				<view class="article_item" v-for="(item,index) in article_list" :key="index" @click="get_index(index)">
					<view class="item_top" @click="to_webview(index)">
						<image :src="article_top_list[index].thumb_media_id" class="item_top_image"></image>
					</view>
					<view class="item_bottom" v-for="(it,ind) in item" :key="ind" @click="to_webviewChild(ind)">
						<view>{{ it.title }}</view>
						<view>
							<image :src="it.thumb_media_id"></image>
						</view>
					</view>
				</view>
				<view class="fill"></view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			all: '',
			li: '',
			zhi: '',
			dai: '',
			wan: '',
			userId: '',
			totalNum: 1,
			article_list: [],
			article_top_list: [],
			article_bottom_list: [],
			RepairOrder: {
				tips_cond: 0, //确认中数量
				tips_accessory: 0, //配件确认数量
				tips_repair: 0, //维修中数量
				tips_confirmmoney: 0, //费用确认中数量
				tips_evalshow: 0 //已完成数量
			},
			confirmation: false, //确认中
			accessory: false, //配件确认
			repair: false, //维修中
			confirmmoney: false, //费用确认
			evalshow: false, //已完成
			InspectionOrder: {
				sistips_cond: 0, //确认中数量检修
				sistips_repair: 0, //巡检中数量检修
				sistips_evalshow: 0 //已完成数量检修
			},
			sisconductshow: false, //确认中
			sisrepair: false, //巡检中
			sisevalshow: false, //已完成
			CaluItem: {} //项目管理数量
		};
	},
	methods: {
		// 验收移交跳转
		toTransfer(e) {
			uni.navigateTo({
				url: `/pagesIndex/projectAdmin/projectAdmin?tabIndex=${e}`
			});
		},
		// 封装维修未登录消息跳转
		notRepair(rStatus, tips, index) {
			if(getApp().globalData.falg != 'true') {
				uni.showModal({
					title: '温馨提示',
					content: '请到首页点击接单',
					success(res) {
						if (res.confirm) {
							uni.switchTab({
								url: 'pages/index/index'
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			} else {
				let data1 = {
					rWorkerId: getApp().globalData.userId,
					rStatus: rStatus
				};
	
				this.$user.updateRStatus(data1).then(res=>{
					this.RepairOrder.tips = 0;
				})
				uni.navigateTo({
					url: '/pagesIndex/release/release?index='+index
				});
			}
		},
		// 封装巡检未登录消息跳转
		notInspection(iStatus, tips, index) {
			if(getApp().globalData.falg != 'true') {
				uni.showModal({
					title: '温馨提示',
					content: '请到首页点击接单',
					success(res) {
						if (res.confirm) {
							uni.switchTab({
								url: 'pages/index/index'
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			} else {
				let data1 = {
					iWorkerId: getApp().globalData.userId,
					iStatus: iStatus
				};
				this.$user.updateUnRead(data1).then(res=>{
					if (res.code == 200) {
						this.InspectionOrder.tips = 0
					}
				})
				uni.navigateTo({
					url: '/pagesIndex/order/order?index='+index
				});
			}
		},
		// 确认中
		to_orderList1() {
			this.notRepair(2, 'tips_cond', 1);
		},
		// 配件确认
		to_orderList2() {
			this.notRepair(3, 'tips_accessory', 2);
		},
		// 维修中
		to_orderList3() {
			this.notRepair(4, 'tips_repair', 3);
		},
		// 费用确认
		to_orderList5() {
			this.notRepair(5, 'tips_confirmmoney', 4);
		},
		// 已完成
		to_orderList4() {
			this.notRepair(6, 'tips_evalshow', 5);
		},
		// 巡检订单
		to_inorderList1() {
			this.notInspection(0, 'sistips_cond', 1);
		},
		to_inorderList2() {
			this.notInspection(2, 'sistips_repair', 2);
		},
		to_inorderList3() {
			this.notInspection(3, 'sistips_evalshow', 3);
		},
		// 跳转到新闻资讯页面
		to_webview(e) {
			let web_url = this.article_top_list[e].url;
			getApp().globalData.web_url = web_url;
			this.$store.dispatch('changeUrl', web_url);
			uni.navigateTo({
				url: '/pagesIndex/webView/webView'
			});
		},
		get_index(e) {
			this.article_bottom_list = this.article_list[e]
		},
		to_webviewChild(e) {
			let web_url = this.article_bottom_list[e].url;
			getApp().globalData.web_url = web_url;
			this.$store.dispatch('changeUrl', web_url);
			uni.navigateTo({
				url: '/pagesIndex/webView/webView'
			});
		},
		//跳转登录
		to_login() {
			uni.navigateTo({
				url: '/login/login'
			});
		},
		// 单个扫码
		SingleCode() {
			if (this.userId == '') {
				this.to_login();
				return;
			}
			uni.scanCode({
				scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
				success(res) {
					let id = res.result;
					let data = {};
					let result = {};
					this.$user.equipId(id,data).then(res=>{
						if (res.code == 200) {
							result = res.data;
							uni.showToast({
								title: '扫码成功',
								icon: 'success',
								duration: 2000
							});
							setTimeout(() => {
								uni.navigateTo({
									url: `/packageA/pages/single_receipt/single_receipt?result=${JSON.stringify(result)}`
								});
							}, 1000);
						} else {
							uni.showToast({
								title: '找不到或已收货',
								icon: 'error',
								duration: 2000
							});
						}
					})
				}
			});
		},
		// 区域收货
		AreaReceiving() {
			if (this.userId == '') {
				this.to_login();
				return;
			}
			uni.navigateTo({
				url: '/pagesIndex/SelectItem/SelectItem?name=area'
			});
		},
		// 批量收获
		BatchReceiving() {
			/* if (this.userId == '') {
				this.to_login();
				return;
			} */
			uni.navigateTo({
				url: '/pagesIndex/SelectItem/SelectItem?name=batch'
			});
		},
		// 批量退货
		BatchReturn() {
			if (this.userId == '') {
				this.to_login();
				return;
			}
			uni.navigateTo({
				url: '/pagesIndex/SelectItem/SelectItem?name=return'
			});
		},
		// 获取项目管理数量
		GetCaluItem() {
			this.$user.getCaluItem().then(res=>{
				this.CaluItem = res.data
			})
		},
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		let userId = getApp().globalData.userId;
		this.GetCaluItem();
		if (userId != undefined) {
			this.userId = userId
			let data = {
				totalNum: this.totalNum
			};
			this.$user.getMaterial(data).then(res=>{
				let dataList = [];
				for(let i in res.data){
					dataList.push(res.data[i]);
				}
				let article_top_list = [];
				for (let i = 0; i < dataList.length; i++) {
					if (dataList[i].length > 1) {
						let dataItem = dataList[i];
						article_top_list.push(dataItem[0]);
						dataItem.splice(0, 1);
					}
				}
				this.article_list = dataList
				this.article_top_list = article_top_list
			})
		}
	},
	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {
		var userId = getApp().globalData.userId;
		if (userId != undefined) {
			// 报修订单
			var data = {
				rWorkerId: userId
			};
			this.$user.getRStatus(data).then(res=>{
				var data = res.data;
				var RepairActions = new Map([
					[2, 'tips_cond'],
					[3, 'tips_accessory'],
					[4, 'tips_repair'],
					[5, 'tips_confirmmoney'],
					[6, 'tips_evalshow']
				]);
				data.forEach((item) => {
					let a = this.RepairActions.get(item.rStatus)
					this.RepairOrder[a] = item.rType;
				});
				var RepairDisplay = new Map([
					['tips_cond-0', ['conductshow', false]],
					['tips_cond-1', ['conductshow', true]],
					['tips_accessory-0', ['accessory', false]],
					['tips_accessory-1', ['accessory', true]],
					['tips_repair-0', ['repair', false]],
					['tips_repair-1', ['repair', true]],
					['tips_confirmmoney-0', ['confirmmoney', false]],
					['tips_confirmmoney-1', ['confirmmoney', true]],
					['tips_evalshow-0', ['evalshow', false]],
					['tips_evalshow-1', ['evalshow', true]]
				]);
				var RepairOrder = this.RepairOrder;
				/* for (let key in RepairOrder) {
					var item = RepairDisplay.get(`${key}-${RepairOrder[key] ? 1 : 0}`);
					this.setData({
						[item[0]]: item[1]
					});
				} */
			})
			// 巡检订单
			var data = {
				iWorkerId: userId
			};
			this.$user.countUnRead(data).then(res=>{
				var data1 = res.data;
				var inspectionActions = new Map([
					[0, 'sistips_cond'],
					[2, 'sistips_repair'],
					[3, 'sistips_evalshow']
				]);
				/* data1.forEach((item) => {
					var setitem = `InspectionOrder.${inspectionActions.get(item.iStatus)}`;
					this.setData({
						[setitem]: item.iPayStatus
					});
				}); */
				var InspectionDisplay = new Map([
					['sistips_cond-0', ['sisconductshow', false]],
					['sistips_cond-1', ['sisconductshow', true]],
					['sistips_repair-0', ['sisrepair', false]],
					['sistips_repair-1', ['sisrepair', true]],
					['sistips_evalshow-0', ['sisevalshow', false]],
					['sistips_evalshow-1', ['sisevalshow', true]]
				]);
				var InspectionOrder = this.InspectionOrder;
				/* for (let key in InspectionOrder) {
					var item = InspectionDisplay.get(`${key}-${InspectionOrder[key] ? 1 : 0}`);
					this.setData({
						[item[0]]: item[1]
					});
				} */
			})
		}
	},
	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {
		if (this.userId != '') {
			let num = this.totalNum + 1;
			this.totalNum = num
			let data = {
				totalNum: this.totalNum
			};
			this.$user.getMaterial(data).then(res=>{
				let dataList = this.article_list;
				for(let i in res.data){
					dataList.push(res.data[i]);
				}
				let article_top_list = this.article_top_list;
				for (let i = 0; i < dataList.length; i++) {
					if (dataList[i].length > 1) {
						let dataItem = dataList[i];
						article_top_list.push(dataItem[0]);
						dataItem.splice(0, 1);
					}
				}
				this.article_list = dataList
				this.article_top_list = article_top_list
			})
		}
	}
};
</script>

<style scoped>
	.operation {
	  width: 100%;
	  height: 1500rpx;
	  background-color: #f8f8f8;
	  display: flex;
	  flex-direction: column;
	}
	
	.banner {
	  width: 100%;
	  height: 387rpx;
	  background-color: #f8f8f8;
	}
	
	.banner swiper {
	  width: 100%;
	  height: 407rpx;
	  margin: 0 auto;
	}
	
	.banner swiper image {
	  width: 90%;
	  height: 90%;
	  border-radius: 20rpx;
	  margin-left: 5%;
	  margin-top: 2.5%;
	}
	
	.orders_type,
	.project_admin,
	.receiving {
	  width: 100%;
	  height: 220rpx;
	  background-color: #f8f8f8;
	  margin-bottom: 20rpx;
	}
	
	.project_admin {
	  height: auto;
	}
	
	.receiving {
	  height: auto;
	}
	
	.project_title {
	  margin-bottom: 20rpx;
	}
	
	.myOrder_title,
	.project_title,
	.receiving_title {
	  width: 90%;
	  height: 50rpx;
	  line-height: 50rpx;
	  margin-left: auto;
	  margin-right: auto;
	  font-size: 28rpx;
	  /* background-color: rebeccapurple; */
	}
	
	.project_content {
	  width: 702rpx;
	  height: 160rpx;
	  margin-left: auto;
	  margin-right: auto;
	  flex-wrap: wrap;
	  display: flex;
	  background: white;
	  border-radius: 20rpx;
	}
	
	.top {
	  text-align: center;
	  margin: 25rpx 0 11rpx 0;
	  color: rgba(51, 51, 51, 1);
	  font-size: 48rpx;
	  font-weight: 700;
	}
	
	.bottom {
	  text-align: center;
	  font-size: 24rpx;
	  font-weight: 400;
	  color: rgba(102, 102, 102, 1);
	}
	.receiving_content {
	  width: 90%;
	  margin-left: auto;
	  margin-right: auto;
	  height: auto;
	  display: flex;
	  justify-content: space-between;
	}
	
	.receiving_content .left,
	.receiving_content .right {
	  width: 324rpx;
	  height: 330rpx;
	  border-radius: 20rpx;
	  display: flex;
	  flex-direction: column;
	  align-items: center;
	  justify-content: center;
	  color: #fff;
	  font-size: 22rpx;
	  background-image: url(https://www.exiushi.com/profile/static/20220812003.png);
	  background-size: 100% 100%;
	}
	
	.receiving_content .left image {
	  width: 98rpx;
	  height: 106rpx;
	}
	
	.receiving_content .right {
	  display: flex;
	  flex-direction: column;
	  justify-content: space-between;
	  background: #fff;
	}
	
	.receiving_content .right .single {
	  width: 100%;
	  height: 150rpx;
	  border-radius: 20rpx;
	  display: flex;
	  justify-content: center;
	  align-items: center;
	  font-size: 32rpx;
	  background-image: url(https://www.exiushi.com/profile/static/20220812001.png);
	  background-size: 100% 100%;
	}
	
	.receiving_content .right .region {
	  background-image: url(https://www.exiushi.com/profile/static/20220812002.png);
	  background-size: 100% 100%;
	}
	
	.right_content {
	  width: 100%;
	  height: 150rpx;
	  display: flex;
	  justify-content: space-between;
	}
	
	.return,
	.region {
	  width: 46%;
	  display: flex;
	  border-radius: 20rpx;
	  flex-direction: column;
	  align-items: center;
	  justify-content: space-evenly;
	  background-image: url(https://www.exiushi.com/profile/static/20220812002.png);
	  background-size: 100% 100%;
	}
	
	.return {
	  background: linear-gradient(92.46deg, rgba(245, 149, 122, 1) 0%, rgba(245, 108, 93, 1) 100%);
	}
	
	.receiving_content .right image {
	  width: 72rpx;
	  height: 72rpx;
	}
	
	.return image,
	.region image {
	  width: 50rpx !important;
	  height: 50rpx !important;
	
	}
	
	.myOrder_list {
	  width: 90%;
	  height: 150rpx;
	  margin-left: auto;
	  margin-right: auto;
	  /* margin-top: 20rpx; */
	  padding-top: 20rpx;
	  display: flex;
	  flex-direction: row;
	}
	
	.myOrder_list_item {
	  width: 20%;
	  height: 150rpx;
	  position: relative;
	}
	
	.tips {
	  background-color: rgb(219, 60, 62);
	  border-radius: 50rpx;
	  font-size: 22rpx;
	  color: #fff;
	  height: 20rpx;
	  line-height: 20rpx;
	  text-align: center;
	  position: absolute;
	  top: 10rpx;
	  right: 25rpx;
	  padding: 5rpx 10rpx;
	}
	
	.item_img {
	  width: 100rpx;
	  height: 100rpx;
	  margin-right: auto;
	  margin-left: auto;
	  /* margin-left: 20rpx; */
	}
	
	.item_img image {
	  width: 88rpx;
	  height: 88rpx;
	  margin: 6rpx 6rpx;
	}
	
	.item_text {
	  width: 100%;
	  height: 50rpx;
	  line-height: 50rpx;
	  text-align: center;
	  font-size: 24rpx;
	  color: #a2a2a2;
	  letter-spacing: 1px;
	}
	
	.article {
	  width: 100%;
	}
	
	.article_title {
	  width: 100%;
	  height: 100rpx;
	  background-color: #f8f8f8;
	}
	
	.article_title view {
	  width: 90%;
	  height: 100%;
	  font-size: 26rpx;
	  font-weight: bold;
	  line-height: 100rpx;
	  text-align: left;
	  color: #333333;
	  margin: 0 auto;
	}
	
	.article_content {
	  width: 100%;
	  background-color: #f8f8f8;
	}
	
	.article_content_center {
	  width: 90%;
	  height: 900rpx;
	  margin: 0 auto;
	  overflow: auto;
	}
	
	.article_item {
	  width: 90%;
	  margin: 40rpx auto;
	  border-radius: 10rpx;
	}
	
	.item_top {
	  width: 100%;
	  height: 200rpx;
	}
	
	.item_top_image {
	  width: 100%;
	  height: 200rpx;
	  border-radius: 10rpx 10rpx 0 0;
	}
	
	.item_top_other {
	  width: 100%;
	  height: 350rpx;
	  border-radius: 10rpx;
	}
	
	.item_top_other_image {
	  width: 100%;
	  height: 350rpx;
	  border-radius: 10rpx;
	}
	
	.item_bottom {
	  width: 100%;
	  height: 150rpx;
	  display: flex;
	  flex-direction: row;
	  background-color: #fff;
	  border-radius: 0 0 10rpx 10rpx;
	}
	
	.item_bottom view:nth-child(1) {
	  width: 70%;
	  height: 100%;
	  /* line-height: 150rpx; */
	  text-align: center;
	  font-size: 24rpx;
	  color: black;
	  padding: 50rpx 10rpx;
	}
	
	.item_bottom view:nth-child(2) {
	  width: 30%;
	  height: 100%;
	}
	
	.item_bottom view:nth-child(2) image {
	  display: block;
	  width: 120rpx;
	  height: 120rpx;
	  margin: 15rpx auto;
	}
	
	.fill {
	  width: 100%;
	  height: 30rpx;
	}
	
	.tips {
	  background-color: rgb(219, 60, 62);
	  border-radius: 50rpx;
	  font-size: 22rpx;
	  color: #fff;
	  height: 20rpx;
	  line-height: 20rpx;
	  text-align: center;
	  position: absolute;
	  top: 10rpx;
	  right: 25rpx;
	  padding: 5rpx 10rpx;
	}
</style>